#include "IntervalTree.h"
#include<iostream>

int main()
{
	interval A[]={{16.3,23.4},{4.56,9.33},{20.8,30},{5.23,9.8},{15.3,33},{17.34,19.9},{22,26.9},{0,3.3},{6,10},{19.33,40}}; //create a interval tree
	int n=sizeof(A)/sizeof(interval);
	
	cout<<"/*---------------------Create Interval Tree-------------------*/"<<endl;
	IntervalTree *T=new IntervalTree();
	T->root=NIL;
	for(int i=0;i<n;i++)
		IntervalT_Insert(T,A[i]);
	cout<<"The interval tree is:"<<endl;
	IntervalT_InorderWalk(T->root);
	cout<<"The root of the tree is:"<<T->root->inte.low<<"   "<<T->root->inte.high<<endl;
	cout<<"/*-------------------------------------------------------------*/"<<endl;
 /*
 *在之前构建的区间树的基础上再输入一个待搜索区间，若该区间与区间树中某一区间相交则输出该区间相关信息（low,high,color,max);否则输出不存在。 
 */
	cout<<"/*--------------------Searching Interval Tree------------------*/"<<endl;
	interval sInt;
	cout<<"Please input the searching interval:";
	cin>>sInt.low>>sInt.high;
	IntervalTNode *sITNode=NIL;
	sITNode=IntervalT_Search(T,sInt);
	if(sITNode==NIL)
		cout<<"The searching interval doesn't exist in the tree."<<endl;
	else{
		cout<<"The overlap interval is:"<<endl;
		cout<<"["<<sITNode->inte.low<<"  "<<sITNode->inte.high<<"]";
		if(sITNode->color==0)
			cout<<"   color:RED     ";
		else
			cout<<"   color:BLACK   ";
		cout<<"Max:"<<sITNode->max<<endl;
		}
		};